<template>
	<el-container>
		<el-header class='x-header'>
			<b class="title">{{ page_info.title }}</b>
			<el-button v-if="$route.query.callback_url" size="mini" icon="el-icon-back" @click="g_page.funcBack">
				返回
			</el-button>
			<el-button type="primary" icon="el-icon-magic-stick" @click="funcUpdateAll" size="mini">
				更新基金参数
			</el-button>
			<el-button size="mini" type="primary" icon="el-icon-search" @click="g_page.funcRedirectEdit(`sh__fund_check__list`)">
				基金参数查询
			</el-button>
			<el-button size="mini" type="success" icon="el-icon-edit" @click="g_page.funcRedirectEdit(`sh__fund__edit`)">
				添加
			</el-button>
			<el-button size="mini" type="danger" icon="el-icon-delete"
					   @click="g_page.funcDel()">删除
			</el-button>
			<el-button size="mini" icon="el-icon-refresh" @click="g_page.funcReload()">刷新</el-button>
		</el-header>
		<el-main class='x-main'>
			<el-form :inline="true" :model="form_q" size="mini">
				<el-form-item label="基金代码">
					<el-input v-model="form_q.compFundCode" placeholder="基金代码"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="g_page.funcSearch">搜索</el-button>
				</el-form-item>
				<br/>
				<el-form-item label="任务提醒时间">
					<el-select v-model="page_info.day">
						<el-option
							v-for="(item,index) in page_info.list_day"
							:value="index"
							:key="index"
							:label="`${item}日`">
						</el-option>
					</el-select>
					<el-button type="primary" @click="funcSetTaskDay">任务时间设置</el-button>
				</el-form-item>
			</el-form>
			<div class="table-wrap">
				<el-table stripe ref="multipleTable" tooltip-effect="dark"
						  @selection-change="g_page.funcTableSelectionChange"
						  :data="list_data">
					<el-table-column type="expand">
						<template slot-scope="data">
							<div class="fund_item">
								<b>1年</b>
								<div>
									排名：<span class="rank_index">{{ data.row.fund_data.y1.rank_index }}</span> /
									{{ data.row.fund_data.y1.rank_total }}
								</div>
								<div>排名占比：{{ data.row.fund_data.y1.proportion }}%</div>
								<div>涨幅：{{ data.row.fund_data.y1.rate }}</div>
								<div>
									<b style="color: red;" v-if="!data.row.fund_data.y1.pass">不符合</b>
									<b style="color:green;" v-else>符合</b>
								</div>
							</div>
							<div class="fund_item">
								<b>6个月</b>
								<div>
									排名：<span class="rank_index">{{ data.row.fund_data.m6.rank_index }}</span> /
									{{ data.row.fund_data.m6.rank_total }}
								</div>
								<div>排名占比：{{ data.row.fund_data.m6.proportion }}%</div>
								<div>涨幅：{{ data.row.fund_data.m6.rate }}</div>
								<div>
									<b style="color: red;" v-if="!data.row.fund_data.m6.pass">不符合</b>
									<b style="color:green;" v-else>符合</b>
								</div>
							</div>
							<div class="fund_item">
								<b>3个月</b>
								<div>
									排名：<span class="rank_index">{{ data.row.fund_data.m3.rank_index }}</span> /
									{{ data.row.fund_data.m3.rank_total }}
								</div>
								<div>排名占比：{{ data.row.fund_data.m3.proportion }}%</div>
								<div>涨幅：{{ data.row.fund_data.m3.rate }}</div>
								<div>
									<b style="color: red;" v-if="!data.row.fund_data.m3.pass">不符合</b>
									<b style="color:green;" v-else>符合</b>
								</div>
							</div>
							<div class="fund_item">
								<b>1个月</b>
								<div>
									排名：<span class="rank_index">{{ data.row.fund_data.m1.rank_index }}</span> /
									{{ data.row.fund_data.m1.rank_total }}
								</div>
								<div>排名占比：{{ data.row.fund_data.m1.proportion }}%</div>
								<div>涨幅：{{ data.row.fund_data.m1.rate }}</div>
								<div>
									<b style="color: red;" v-if="!data.row.fund_data.m1.pass">不符合</b>
									<b style="color:green;" v-else>符合</b>
								</div>
							</div>
						</template>
					</el-table-column>
					<el-table-column type="selection"></el-table-column>
					<el-table-column label="基金编码">
						<template slot-scope="data">
							{{ data.row.fund_code }}
						</template>
					</el-table-column>
					<el-table-column label="基金名称">
						<template slot-scope="data">
							{{ data.row.fund_name }}
						</template>
					</el-table-column>
					<el-table-column label="符合条件">
						<template slot-scope="data">
							<div style="color: green;" v-if="data.row.fund_errcode==0">满足条件</div>
							<div style="color:red;" v-else>不满足</div>
						</template>
					</el-table-column>
					<el-table-column label="状态">
						<template slot-scope="data">
							<div v-if="data.row.fund_enable==1">有效</div>
							<b style="color:red;" v-else>无效</b>
						</template>
					</el-table-column>
					<el-table-column label="排序">
						<template slot-scope="data">
							{{ data.row.fund_order }}
						</template>
					</el-table-column>
					<el-table-column fixed="right" label="操作">
						<template slot-scope="data">
							<el-button type="primary" size="mini" @click="g_page.funcRedirectEdit('sh__fund__edit',data.row)">
								编辑
							</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</el-main>
		<!---->
		<!---->
		<!-- 分页 -->
		<el-footer v-if="page_show" class="x-page">
			<el-pagination class="paging" background layout="total, sizes, prev, pager, next, jumper"
						   @current-change="g_page.funcPageChange" :page-sizes="[page_size]"
						   :current-page="page_index" :page-size="page_size" :total="page_total">
			</el-pagination>
		</el-footer>
		<!---->
		<!---->
		<!-- 弹框 -->
		<el-dialog :title="form.app_idx+'配置'" :visible.sync="form_dialog_visible" width="70%">
			<el-form ref="form" :rules="form_rules" :model="form" size="mini" label-width="15%">
				<el-form-item label="入口链接" v-if="!g_page.funcIsAdminAdd()">
					<el-input :disabled="true" v-model="form.oauth_url"/>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="g_page.funcBack" size="mini">取消</el-button>
				<el-button type="success" @click="g_page.funcSave" size="mini">保存</el-button>
			</div>
		</el-dialog>
		<!---->
		<!---->
		<!---->
	</el-container>
</template>


<script>
	export default {
		data() {
			let page_data = { super_uid: '' }
			//
			page_data = this.g_cc.funcGetInitData(page_data)
			//
			return page_data
		},
		mounted() {
			console.log('mounted')
			//
			this.g_page.funcSetVue(this)
			// 应用ID
			this.g_page.funcSetApiUrlList('/xadmin/sh/sh__fund__list')
			this.g_page.funcSetApiUrlDel('/xadmin/sh/sh__fund__list/del')
			//页码
			this.g_page.funcSetPageSize(30)
			//搜索
			this.form_q = {
				'compKw': ''
			}
			this.g_page.funcGetList()
			//
			this.form_rules = {
				acc_uidX: [
					{
						required: true,
						message: '必填',
						trigger: 'blur'
					}
				]
			}
			//
		},
		methods: {
			////////////////////
			//更新基金参数
			funcUpdateAll() {
				this.g_cc.func_confirm('更新基金参数，确定吗？', () => {
					this.funcUpdateAllApi()
				})
			},
			////////////////////
			//更新基金参数api
			funcUpdateAllApi() {
				this.g_cc.func_axios({
					url: '/xadmin/sh/sh__fund__list/funcUpdateAll',
					data: {},
					// loading: false,
					success: (res) => {
						//
						if (res.data.errcode == 0) {
							this.g_cc.func_alert('更新成功', 'success', () => {
								this.g_page.funcGetList()
							})
						} else {
							this.g_cc.func_alert(res.data.errmsg, 'error')
						}
					}
					//
				})
			},
			////////////////////
			//更新任务提醒日期
			funcSetTaskDay() {
				this.g_cc.func_axios({
					url: '/xadmin/sh/sh__fund__list/funcSetTaskDay',
					data: {
						day: this.page_info.day
					},
					// loading: false,
					success: (res) => {
						//
						if (res.data.errcode == 0) {
							this.g_cc.func_alert('更新成功', 'success', () => {
								this.g_page.funcGetList()
							})
						} else {
							this.g_cc.func_alert(res.data.errmsg, 'error')
						}
					}
					//
				})
			}
			////////////////////
		}
	}
</script>

<style scoped>
	.fund_item {
		float: left;
		margin: 0 20px 0px 0;
	}

	.rank_index {
		color: blue;
	}
</style>
